<?php

?><html><?php
?><head><?php
?><style>
body {
    margin: 5em;
}
table {
    empty-cells: show;
    border-collapse: collapse;
    border-spacing: 0px;
    font-family: 'Calibry', sans-serif;
    font-size: 85%;
}
table th,
table tr,
table td {
    border: 1px solid #777777;
}
table tr.altrow {
    background-color: #F0F0F0;
}
.align-r {
    text-align: right;
}
.align-c {
    text-align: center;
}
.align-l {
    text-align: left;
}
em {
    color: 999999;
}
td, th {
    padding: 0.1em 0.5em;
    vertical-align: bottom;
}
</style><?php
?></head><?php
?><body><?php

?><form method="POST"><?php
?><p><?php
?><label for="string"><?php
echo "Enter query:"
?></label><?php
?><br /><?php
?><textarea name="string" rows="10" cols="100"><?php

echo htmlspecialchars($string, ENT_NOQUOTES, "UTF-8");

?></textarea><?php
?></p><?php
?><p><?php
?><input type="submit" value="Execute" /><?php

?></p><?php
?></form><?php

if ($submit) {
    if (isset($result)) {
        if ($result["type"] == "change") {
            ?><p><?php
                echo htmlspecialchars("Affected rows: ".$result["num"], ENT_NOQUOTES, "UTF-8");
            ?></p><?php
            ?><p><?php
                echo "Time: ";
                echo round($result["time"], 4);
                echo " s";
            ?></p><?php
        } elseif ($result["type"] == "select") {
            ?><p><?php
                echo htmlspecialchars("Rows: ".$result["num"], ENT_NOQUOTES, "UTF-8");
            ?></p><?php
            ?><p><?php
                echo "Time: ";
                echo round($result["time"], 4);
                echo " s";
            ?></p><?php
            if ($result["num"] > 0) {
                ?><table><?php
                foreach ($result["headers"] as $col_num => $header) {
                    if ($result["types"][$col_num]["type"] == "numeric") {
                        ?><col class="align-r" /><?php
                    } else {
                        ?><col /><?php
                    }
                }
                ?><tr><?php
                foreach ($result["headers"] as $header) {
                    ?><th><?php
                        echo htmlspecialchars($header, ENT_NOQUOTES, "UTF-8");
                    ?></th><?php
                }
                ?></tr><?php
                $odd = 0;
                foreach ($result["rows"] as $row) {
                    if (++$odd % 2) {
                        ?><tr class="altrow"><?php
                    } else {
                        ?><tr><?php
                    }
                    foreach ($row as $col_num => $col) {
                        if ($result["types"][$col_num]["numeric"]) {
                            ?><td class="align-r"><?php
                        } else {
                            ?><td><?php
                        }
                        if (is_null($col)) {
                            ?><em><?php
                            echo "null";
                            ?></em><?php
                        } else {
                            if ($result["types"][$col_num]["binary"]) {
                                ?><em><?php
                                echo "binary";
                                ?></em><?php
                            } else {
                                echo htmlspecialchars($col, ENT_NOQUOTES, "UTF-8");
                            }
                        }
                        ?></td><?php
                    }
                    ?></tr><?php
                }
                ?></table><?php
            }
        }
    } else {
        ?><h1><?php
            echo "Error";
        ?></h1><?php
        ?><p><?php
            echo htmlspecialchars($e->getCode().": ".$e->getMessage(), ENT_NOQUOTES, "UTF-8");
        ?></p><?php
    }
}

?></body><?php
?></html><?php

?>